package org.javaboy.swagger2.controller;

import com.sanbi.common.vo.ResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.javaboy.swagger2.bean.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;

/**
 * @Author 江南一点雨
 * @Site www.javaboy.org 2019-06-05 9:38
 */
@RestController
@Api(tags = "测试接口")
@RequestMapping("test")
public class TestController {

    @ApiOperation("根据id查询用户")
    @ApiImplicitParam(name = "id", value = "用户id", defaultValue = "99")
    @GetMapping("getUserById")
    public User getUserById(Long id) {
        User user = new User();
        user.setId(id);
        return user;
    }

    @GetMapping("getAppTime")
    public ResponseVo getAppTime() {
        return ResponseVo.ok(LocalDateTime.now());
    }

    @ApiOperation("根据id更新用户名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", defaultValue = "99"),
            @ApiImplicitParam(name = "username", value = "用户名", defaultValue = "javaboy")
    })
    @PutMapping("updateUsernameById")
    public User updateUsernameById(String username, Long id) {
        User user = new User();
        user.setId(id);
        user.setUsername(username);
        return user;
    }

    @PostMapping("addUser")
    @ApiOperation("添加用户")
    public User addUser(@RequestBody User user) {
        return user;
    }

    @DeleteMapping("deleteUserById/{id}")
    @ApiOperation("根据id 删除用户")
    public void deleteUserById(@PathVariable Long id) {

    }

    @GetMapping("page1")
    public String page1() {
        return "I'm page AAA";
    }

    @GetMapping("page2")
    public String page2() {
        return "I'm page BBB";
    }

    @GetMapping("page3")
    public void page3(HttpServletResponse response) throws IOException {
        response.sendRedirect("/test/page1");
    }
}
